/**
 * Copyright &copy; 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
 */
package com.z100h.supplychain.evidence.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import com.jeeplus.core.persistence.BaseMapper;
import com.jeeplus.core.persistence.annotation.MyBatisMapper;
import com.z100h.supplychain.evidence.entity.StockoutSku;
import com.z100h.supplychain.evidence.entity.StockoutSkuVo;

/**
 * 出库skuMAPPER接口
 * @author madara
 * @version 2019-01-18
 */
@MyBatisMapper
public interface StockoutSkuMapper extends BaseMapper<StockoutSku> {

	/**
	 * 根据传入的resid 聚合sku数量
	 * @param stockoutSku
	 * @return
	 */
	public List<StockoutSku> findResourceIdGroupBySkuId(StockoutSku stockoutSku);

	/**
	 * 根据凭证单号查询所有sku剩余 数量
	 * @param stockoutSku
	 * @return
	 */
	public List<StockoutSku> findSkuAmountOut(StockoutSku stockoutSku);

	public List<StockoutSku> findStockoutSkuByEvidenceId(String evidenceId);

	public List<StockoutSku> findStockoutSkuByOrderIds(@Param("orderIds") List<String> orderIds);

	public List<StockoutSku> findStockoutSkuByStockroomId(String stockroomId);

	public List<StockoutSku> findRepairoutSkuByEvidenceId(String evidenceId);

	/**
	 * 
	 * 根据凭证id查询未出库的sku
	 * 
	 * @param evidenceId
	 * @return
	 * @author: Fyh - 1009173473@qq.com 
	 * @date: Created on 2019年5月15日 上午9:51:27
	 */
	public List<StockoutSku> findUnStockoutSkuListByEvidenceId(String evidenceId);

	public void updateStockoutSkuAmountOut(@Param("evidenceId") String evidenceId, @Param("skuId") Integer skuId,
			@Param("amount") Integer amount);

	public void updateStockoutSkuAmountIncrementOut(@Param("evidenceId") String evidenceId,
			@Param("skuId") Integer skuId, @Param("amount") Integer amount);

	public List<StockoutSkuVo> findSkuNotStockout(String companyId);

	public void insertOrderAndRepair(@Param("evidenceId") String evidenceId,
			@Param("stockoutSku") StockoutSku stockoutSku);

	public List<StockoutSku> findSkuByEvidenceIds(@Param("evidenceIds") List<String> evidenceIds);

	@Select("SELECT a.sku_id AS skuId FROM sc_e_stockout_sku a where a.evidence_id = #{evidenceId} AND a.amount <> IFNULL(a.amount_out,0)")
	public List<String> findUnfinishSkuByEid(@Param("evidenceId") String evidenceId);

}